import { UnsupportedMediaTypeException, UseInterceptors, applyDecorators } from '@nestjs/common'
import { FileInterceptor } from '@nestjs/platform-express'

export const Upload = (name = 'file', fileType = 'iimage') => {
   return applyDecorators(
      UseInterceptors(
         FileInterceptor(name, {
            fileFilter(req, file, callback: (error: Error | null, acceptFile: boolean) => void) {
               if (file.mimetype.includes(fileType)) {
                  callback(null, true)
               } else {
                  callback(new UnsupportedMediaTypeException('文件类型错误'), false)
               }
            }
         })
      )
   )
}
